package com.cskaoyan.shopping.service.impl;

import com.cskaoyan.shopping.dal.entitys.ItemCat;
import com.cskaoyan.shopping.dal.persistence.ItemCatMapper;
import com.cskaoyan.shopping.dto.ProductCateDto;
import com.cskaoyan.shopping.service.IProductCateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Condition;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName:IProductCateServiceImpl
 * @Description:TODO
 * @author:leiwenjie
 * @date:2022/9/20 22:03
 * @version:1.0
 */
@Service
public class IProductCateServiceImpl implements IProductCateService {

    @Autowired
    ItemCatMapper itemCatMapper;



    @Override
    public List<ProductCateDto> getAllProductCate() {

        Condition condition = new Condition(ItemCat.class);
        condition.setOrderByClause("sort_order asc");
        List<ItemCat> itemCats = itemCatMapper.selectByExample(condition);

        List<ProductCateDto> cats = new ArrayList<>();

        for (ItemCat itemCat : itemCats) {
            ProductCateDto cateDto = new ProductCateDto();
            cateDto.setIconUrl(itemCat.getIcon());
            cateDto.setName(itemCat.getName());
            cateDto.setId(itemCat.getId());
            cateDto.setIsParent(itemCat.getIsParent());
            cateDto.setParentId(itemCat.getParentId());
            cats.add(cateDto);
        }
        return cats;



    }
}
